/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package xpath;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 *
 * @author PeSu
 */
public class convertHTML {
    public static String readPage(String url) 
    {
        try
        {
		URL u = new URL(url);
		HttpURLConnection con = (HttpURLConnection) u.openConnection();
		InputStream is = con.getInputStream();
		BufferedReader reader = new BufferedReader(new InputStreamReader(is));		
		char[] buffer = new char[8192];
		int read = 0;
		StringBuilder sb = new StringBuilder();
		
		while ((read = reader.read(buffer)) != -1)
			sb.append(buffer, 0, read);
                
		String text= sb.toString();
                /*File f = new File("text.html");
                BufferedWriter b = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f)));
                b.write(text);
                b.close();*/
                return text;
        }catch(Exception ex)
        {            
            return"";
	}
    }
}
